package com.example.shareapp.utils;

import android.content.Context;
import android.widget.Toast;

import com.example.shareapp.bean.AllDataEntry;
import com.google.gson.JsonObject;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class JsonObjectUtils {

  public static AllDataEntry getAllDataEnty(String str){
      AllDataEntry mAllDataEntry = new AllDataEntry();
      try {
          JSONObject mJSONObject  = new JSONObject (str);
          if (mJSONObject.has("msg")){
              mAllDataEntry.msg = mJSONObject.optString("msg");
          }
          if (mJSONObject.has("code")){
              mAllDataEntry.code = mJSONObject.optString("code");
          }

          if ("0".equals(mAllDataEntry.code)){
              if (mJSONObject.has("data")){
                  JSONObject dataJson = mJSONObject.optJSONObject("data");

                    try {

                        if (dataJson.has("aQq")){
                            JSONObject aQqjson = dataJson.optJSONObject("aQq");
                            AllDataEntry.AQQ aqq = new AllDataEntry.AQQ();
                            if (aQqjson.has("searchValue")){
                                aqq.searchValue = aQqjson.optString("searchValue");
                            }
                            if (aQqjson.has("createBy")){
                                aqq.createBy = aQqjson.optString("createBy");
                            }
                            if (aQqjson.has("createTime")){
                                aqq.createTime = aQqjson.optString("createTime");
                            }
                            if (aQqjson.has("updateBy")){
                                aqq.updateBy = aQqjson.optString("updateBy");
                            }
                            if (aQqjson.has("updateTime")){
                                aqq.updateTime = aQqjson.optString("updateTime");
                            }
                            if (aQqjson.has("remark")){
                                aqq.remark = aQqjson.optString("remark");
                            }



                            if (aQqjson.has("id")){
                                aqq.id = aQqjson.optString("id");
                            }
                            if (aQqjson.has("name")){
                                aqq.name = aQqjson.optString("name");
                            }
                            if (aQqjson.has("qq")){
                                aqq.qq = aQqjson.optString("qq");
                            }
                            if (aQqjson.has("ctime")){
                                aqq.ctime = aQqjson.optString("ctime");
                            }
                            if (aQqjson.has("isactive")){
                                aqq.isactive = aQqjson.optString("isactive");
                            }

                            mAllDataEntry.aqq = aqq;

                        }


                  }catch (Exception e){
                        e.printStackTrace();
                    }
                  mAllDataEntry.liebiaosList = new ArrayList<>();
                    try {
                        if (dataJson.has("aRuanjianLiebiaos")){
                            JSONArray jsonArray = dataJson.optJSONArray("aRuanjianLiebiaos");
                            if (jsonArray != null && jsonArray.length() > 0){
                                List<AllDataEntry.ARuanjianLiebiaos> liebiaosList = new ArrayList<>();
                                for (int i = 0;i<jsonArray.length();i++){
                                    JSONObject object = jsonArray.getJSONObject(i);
                                    AllDataEntry.ARuanjianLiebiaos liebiaos = new AllDataEntry.ARuanjianLiebiaos();
                                    if (object.has("searchValue")){
                                        liebiaos.searchValue = object.optString("searchValue");
                                    }
                                    if (object.has("createBy")){
                                        liebiaos.createBy = object.optString("createBy");
                                    }
                                    if (object.has("createTime")){
                                        liebiaos.createTime = object.optString("createTime");
                                    }
                                    if (object.has("updateBy")){
                                        liebiaos.updateBy = object.optString("updateBy");
                                    }
                                    if (object.has("updateTime")){
                                        liebiaos.updateTime = object.optString("updateTime");
                                    }
                                    if (object.has("remark")){
                                        liebiaos.remark = object.optString("remark");
                                    }


                                    if (object.has("id")){
                                        liebiaos.id = object.optString("id");
                                    }
                                    if (object.has("name")){
                                        liebiaos.name = object.optString("name");
                                    }
                                    if (object.has("path")){
                                        liebiaos.path = object.optString("path");
                                    }
                                    if (object.has("text")){
                                        liebiaos.text = object.optString("text");
                                    }
                                    if (object.has("url")){
                                        liebiaos.url = object.optString("url");
                                    }
                                    if (object.has("ctime")){
                                        liebiaos.ctime = object.optString("ctime");
                                    }
//                                    int num = (int)(Math.random()*10+1);
//                                    if (num == 10){
//                                        num = 9;
//                                    }
//                                    liebiaos.xzcs = ""+((int)(Math.random() * 900 + 100)+"."+num+"万次");

                                    liebiaos.xzcs = ""+(i * 3 + 524)+"."+(2)+"万次";
                                    if (object.has("isactive")){
                                        liebiaos.isactive = object.optString("isactive");
                                    }



                                    liebiaosList.add(liebiaos);
                                }

                                mAllDataEntry.liebiaosList = liebiaosList;
                            }
                        }

                    }catch (Exception e){
                        e.printStackTrace();
                    }

                    try {

                        if (dataJson.has("aErweima")){
                            JSONObject ewJson = dataJson.optJSONObject("aErweima");
                            AllDataEntry.AErweima aErweima = new AllDataEntry.AErweima();
                            if (ewJson.has("searchValue")){
                                aErweima.searchValue = ewJson.optString("searchValue");
                            }
                            if (ewJson.has("createBy")){
                                aErweima.createBy = ewJson.optString("createBy");
                            }
                            if (ewJson.has("createTime")){
                                aErweima.createTime = ewJson.optString("createTime");
                            }
                            if (ewJson.has("updateBy")){
                                aErweima.updateBy = ewJson.optString("updateBy");
                            }
                            if (ewJson.has("updateTime")){
                                aErweima.updateTime = ewJson.optString("updateTime");
                            }
                            if (ewJson.has("remark")){
                                aErweima.remark = ewJson.optString("remark");
                            }

                            if (ewJson.has("id")){
                                aErweima.id = ewJson.optString("id");
                            }
                            if (ewJson.has("name")){
                                aErweima.name = ewJson.optString("name");
                            }
                            if (ewJson.has("path")){
                                aErweima.path = ewJson.optString("path");
                            }
                            if (ewJson.has("text")){
                                aErweima.text = ewJson.optString("text");
                            }
                            if (ewJson.has("url")){
                                aErweima.url = ewJson.optString("url");
                            }
                            if (ewJson.has("ctime")){
                                aErweima.ctime = ewJson.optString("ctime");
                            }
                            if (ewJson.has("isactive")){
                                aErweima.isactive = ewJson.optString("isactive");
                            }

                            mAllDataEntry.aErweima = aErweima;

                        }

                    }catch (Exception e){
                        e.printStackTrace();
                    }



                  try {

                      if (dataJson.has("aLuoliZhibo")){
                          JSONObject luoliZhiboJson = dataJson.optJSONObject("aLuoliZhibo");
                          AllDataEntry.ALuoliZhibo aLuoliZhibo = new AllDataEntry.ALuoliZhibo();
                          if (luoliZhiboJson.has("searchValue")){
                              aLuoliZhibo.searchValue = luoliZhiboJson.optString("searchValue");
                          }
                          if (luoliZhiboJson.has("createBy")){
                              aLuoliZhibo.createBy = luoliZhiboJson.optString("createBy");
                          }
                          if (luoliZhiboJson.has("createTime")){
                              aLuoliZhibo.createTime = luoliZhiboJson.optString("createTime");
                          }
                          if (luoliZhiboJson.has("updateBy")){
                              aLuoliZhibo.updateBy = luoliZhiboJson.optString("updateBy");
                          }
                          if (luoliZhiboJson.has("updateTime")){
                              aLuoliZhibo.updateTime = luoliZhiboJson.optString("updateTime");
                          }
                          if (luoliZhiboJson.has("remark")){
                              aLuoliZhibo.remark = luoliZhiboJson.optString("remark");
                          }

                          if (luoliZhiboJson.has("id")){
                              aLuoliZhibo.id = luoliZhiboJson.optString("id");
                          }
                          if (luoliZhiboJson.has("name")){
                              aLuoliZhibo.name = luoliZhiboJson.optString("name");
                          }
                          if (luoliZhiboJson.has("path")){
                              aLuoliZhibo.path = luoliZhiboJson.optString("path");
                          }
                          if (luoliZhiboJson.has("text")){
                              aLuoliZhibo.text = luoliZhiboJson.optString("text");
                          }
                          if (luoliZhiboJson.has("url")){
                              aLuoliZhibo.url = luoliZhiboJson.optString("url");
                          }
                          if (luoliZhiboJson.has("ctime")){
                              aLuoliZhibo.ctime = luoliZhiboJson.optString("ctime");
                          }
                          if (luoliZhiboJson.has("isactive")){
                              aLuoliZhibo.isactive = luoliZhiboJson.optString("isactive");
                          }

                          mAllDataEntry.aLuoliZhibo = aLuoliZhibo;

                      }

                  }catch (Exception e){
                      e.printStackTrace();
                  }

                  try {

                      if (dataJson.has("aBanner")){
                          JSONObject aBannerjson = dataJson.optJSONObject("aBanner");
                          AllDataEntry.ABanner aBanner = new AllDataEntry.ABanner();
                          if (aBannerjson.has("searchValue")){
                              aBanner.searchValue = aBannerjson.optString("searchValue");
                          }
                          if (aBannerjson.has("createBy")){
                              aBanner.createBy = aBannerjson.optString("createBy");
                          }
                          if (aBannerjson.has("createTime")){
                              aBanner.createTime = aBannerjson.optString("createTime");
                          }
                          if (aBannerjson.has("updateBy")){
                              aBanner.updateBy = aBannerjson.optString("updateBy");
                          }
                          if (aBannerjson.has("updateTime")){
                              aBanner.updateTime = aBannerjson.optString("updateTime");
                          }
                          if (aBannerjson.has("remark")){
                              aBanner.remark = aBannerjson.optString("remark");
                          }



                          if (aBannerjson.has("id")){
                              aBanner.id = aBannerjson.optString("id");
                          }
                          if (aBannerjson.has("name")){
                              aBanner.name = aBannerjson.optString("name");
                          }
                          if (aBannerjson.has("path")){
                              aBanner.path = aBannerjson.optString("path");
                          }
                          if (aBannerjson.has("ctime")){
                              aBanner.ctime = aBannerjson.optString("ctime");
                          }
                          if (aBannerjson.has("url")){
                              aBanner.url = aBannerjson.optString("url");
                          }

                          if (aBannerjson.has("isactive")){
                              aBanner.isactive = aBannerjson.optString("isactive");
                          }

                          mAllDataEntry.aBanner = aBanner;

                      }


                  }catch (Exception e){
                      e.printStackTrace();
                  }

                  try {

                      if (dataJson.has("aGengduoruanjian")){
                          JSONObject aaGengduoruanjianjson = dataJson.optJSONObject("aGengduoruanjian");
                          AllDataEntry.AGengDuoRuanJian aGengduoruanjian = new AllDataEntry.AGengDuoRuanJian();
                          if (aaGengduoruanjianjson.has("searchValue")){
                              aGengduoruanjian.searchValue = aaGengduoruanjianjson.optString("searchValue");
                          }
                          if (aaGengduoruanjianjson.has("createBy")){
                              aGengduoruanjian.createBy = aaGengduoruanjianjson.optString("createBy");
                          }
                          if (aaGengduoruanjianjson.has("createTime")){
                              aGengduoruanjian.createTime = aaGengduoruanjianjson.optString("createTime");
                          }
                          if (aaGengduoruanjianjson.has("updateBy")){
                              aGengduoruanjian.updateBy = aaGengduoruanjianjson.optString("updateBy");
                          }
                          if (aaGengduoruanjianjson.has("updateTime")){
                              aGengduoruanjian.updateTime = aaGengduoruanjianjson.optString("updateTime");
                          }
                          if (aaGengduoruanjianjson.has("remark")){
                              aGengduoruanjian.remark = aaGengduoruanjianjson.optString("remark");
                          }

                          if (aaGengduoruanjianjson.has("id")){
                              aGengduoruanjian.id = aaGengduoruanjianjson.optString("id");
                          }
                          if (aaGengduoruanjianjson.has("name")){
                              aGengduoruanjian.name = aaGengduoruanjianjson.optString("name");
                          }
                          if (aaGengduoruanjianjson.has("url")){
                              aGengduoruanjian.url = aaGengduoruanjianjson.optString("url");
                          }
                          if (aaGengduoruanjianjson.has("ctime")){
                              aGengduoruanjian.ctime = aaGengduoruanjianjson.optString("ctime");
                          }
                          if (aaGengduoruanjianjson.has("isactive")){
                              aGengduoruanjian.isactive = aaGengduoruanjianjson.optString("isactive");
                          }

                          mAllDataEntry.aGengduoruanjian = aGengduoruanjian;

                      }


                  }catch (Exception e){
                      e.printStackTrace();
                  }


              }
          }
      }catch (Exception e){
          e.printStackTrace();
      }
      return mAllDataEntry;

  }

}
